﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace GameWP
{
    public class Treasure : Character
    {
#region Methods
        public void Reset()
        {
            _hp = _hpmax;
            _indexTexture = 0;
            _state = State.Move;
        }
#endregion

#region Initiation
        public Treasure(List<Texture2D> listTextures,
            Vector2 posotion, 
            int hp, 
            float delay,
            float scaleTexture): base(listTextures, posotion, hp, 0, 0, delay, scaleTexture, 0, null)
        {
            _listTextures = listTextures;
            _position = posotion;
            _hp = hp;
            _hpmax = _hp;
            _delay = delay;
            _scaleTexture = scaleTexture;
            _scaleRect = -100;
            _rectangle = new Rectangle
                ((int)_position.X, (int)_position.Y, _listTextures[0].Width - 50, _listTextures[0].Height - 50);
            _indexTexture = 0;
            _state = State.Move;

            //HpBar
            _hpBar = new HpBar(_hp, new Vector2(140, 220), Color.Yellow);
        }
#endregion

#region Update & Draw
        public override void Update(GameTime gametime, Vector2 position)
        {
            _hpBar.Hp = _hp;
            if (_hp <= 0)
            {
                double gt = gametime.TotalGameTime.Milliseconds;
                if ((gt % NormalDelay) < _delay)
                {
                    _indexTexture++;
                    if (_indexTexture >= _listTextures.Count)
                    {
                        _indexTexture = _listTextures.Count - 1;
                        _state = State.Disappear;
                    }
                    
                }
                _hp = 0;
            }
            _hpBar.Update(gametime, _hpBar.Position, _hpBar.Hp);
        }

        public override void Draw(SpriteBatch spritebatch, GameTime gametime)
        {
            spritebatch.Draw(_listTextures[_indexTexture], _position, null, _colorTexture, 0, Vector2.Zero, _scaleTexture, SpriteEffects.None, 0);
            _hpBar.Draw(spritebatch, gametime);
        }
#endregion
    }
}
